// pages/class/index.js
const $api = require("../../api/class").API
const $message = require("../../api/message").API
const $banner = require("../../api/banner").API


Page({

  /**
   * 页面的初始数据
   */
  data: {
    bannerList:[],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 2000,
    duration: 500,
    page:1,
    msglists:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var t = this
    t.getBannerByOwnerShip()
  },
  onShow:function(){
    var t = this
    t.setData({
      page:1,
      msglists:[]
    })
    t.getMessageList()

    t.getClassAttendanceStatistics()
  },
  onReachBottom:function(){
    var t = this
    t.setData({
      page:t.data.page +1 
    })
    t.getMessageList()

  },
  // 跳转消息通知
  gotomessage(e){
    var t = this
    wx.navigateTo({
      url:'/pages/message/index'
    })
  },
  // 跳转班级监控
  gotomoitor(e){
    var t = this
    wx.navigateTo({
      url:'/pages/monitor/index'
    })
  },
  gotoattendance(e){
    var t = this
    wx.navigateTo({
      url:'/pages/class/attendance/index'
    })
  },
  gototask(e){
    var t = this
    wx.navigateTo({
      url:'/classes/pages/task/index'
    })
  },
  gotochooseclass(e){
    var t = this
    wx.navigateTo({
      url:'/classes/pages/chooseclass/index'
    })
  },
  gotostudentlists(e){
    var t = this
    wx.navigateTo({
      url:'/classes/pages/studentlists/index'
    })
  },
   // 消息列表
   getMessageList(){
    var t = this,
    data = {
      member_id:wx.getStorageSync('memberinfo').member_id,
      message_type:"all",
      pageNo:t.data.page,
      child_id:"",
    }
    $message.getMessageList(data).then(res=>{
      var msglists = t.data.msglists
      msglists = msglists.concat(res.data)
      t.setData({
        msglists:msglists
      })
    })
   },
   getClassAttendanceStatistics(){
     var t = this,
     data = {
      class_id:wx.getStorageSync('TeacherClassinfo').class_id
     }
     $api.getClassAttendanceStatistics(data).then(res=>{
       console.log(res)
       t.setData({
        absence:res.data.absence,
        attendance:res.data.attendance
       })
     })
   },
   gotomessageinfo(e){
    var t = this
    wx.navigateTo({
      url:'/pages/message/info/index?id='+e.currentTarget.dataset.id
    })
  },
  // 根据位置获取不同的banner列表
  getBannerByOwnerShip(){
    var t = this,
    data = {
        banner_ownership:6
    }
    $banner.getBannerByOwnerShip(data).then(res=>{
        console.log(res)
        t.setData({
            interval:res.data.banner_refresh,
            bannerList:res.data.detail_list
        })
    })
},
})